
package com.ruipengkj.model;
/**
 * 说明：
 * 仓库管理model
 * @Author：孙航
 */
import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.ruipengkj.bean.TShopMemberLevel;


public class MemberLevelModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas=new Vector<List<Object>>();
	private Vector<String> columns = new Vector<String>();
	public MemberLevelModel(){
		columns.add("级别编号");
		columns.add("级别名称");
		columns.add("是否有折扣");
		columns.add("折扣");
		columns.add("阀值");
		columns.add("级别");
		columns.add("阀值类型");
		columns.add("会员权限描述");
		columns.add("类型");
	}
	//获得行数
	public int getRowCount(){
		return rowdatas.size();
	}
	//获得列数
	public int getColumnCount(){
		return columns.size();
	}
	//获得单元格的值
	public Object getValueAt(int row,int column){
		
		return ((Vector)rowdatas.get(row)).get(column);
	}
	//获取列名
	public String getColumnName(int column){
		return (String)columns.get(column);
	}
	

	//设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		if(columns.size()-1==columnIndex||columns.size()-2==columnIndex){
			return true;
		}
		return false;
	}
	
	public void removeData(int row){
		rowdatas.remove(row);
	}
	
	
	
	//设置单元格的值
	public void setValueAt(Object aValue,int rowIndex,int columnIndex){
		//取出对应的记录
		Vector rowdata = (Vector)rowdatas.get(rowIndex);
		//删除原来的值
		rowdata.remove(columnIndex);
		//添加用户新修改的值
		rowdata.add(columnIndex,aValue);
	}


	public void setRowData(List<TShopMemberLevel> tShopMemberLevelList) {
		rowdatas.clear();
		if(tShopMemberLevelList != null && tShopMemberLevelList.size() != 0){
			for(int i = 0;i < tShopMemberLevelList.size();i++){
				TShopMemberLevel tShopMemberLevel = tShopMemberLevelList.get(i);
				List<Object> row=new Vector<Object>();
				row.add(tShopMemberLevel.getLevelID());
				row.add(tShopMemberLevel.getName());
				if(tShopMemberLevel.isIsDiscount()){
					row.add("是");
				}else{
					row.add("否");
				}
				row.add(tShopMemberLevel.getDiscount());
				row.add(tShopMemberLevel.getWalve());
				row.add(tShopMemberLevel.getLevel());
				if(tShopMemberLevel.getWalveType()==1){
					row.add("消费积分");
				}else if(tShopMemberLevel.getWalveType()==2){
					row.add("充值积分");
				}
				row.add(tShopMemberLevel.getDes());
				if(tShopMemberLevel.getType()==1){
					row.add("系统级别");
				}else{
					row.add("自定义级别");
				}
				
				rowdatas.add(row);
			}
		}
	}
	
	
}
